package com.gorun.wechat.utils;/**
 * Created by moneylee on 2019/4/19.
 */

import java.io.*;

/**
 * @className: FileUtil
 * @Description: 文件工具类
 * @Author moneylee
 * @Date 2019/4/19 下午1:44
 * @Version 1.0
 **/
public class FileUtil {

    public static File saveFile(InputStream inputStream, String fileName) {

        OutputStream outputStream = null;
        File output = new File(fileName);

        try {
            outputStream = new FileOutputStream(output);
            byte[] buffer = new byte[1024];
            int len = 0;
            while ((len = inputStream.read(buffer)) != -1) {
                outputStream.write(buffer, 0, len);
            }
            outputStream.flush();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (inputStream != null) {
                    inputStream.close();
                }
                if (outputStream != null) {
                    outputStream.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        return output;
    }


}
